package com.link2room.aeriabots.controller.inside;

import com.link2room.aeriabots.dto.result.base.WxMemberInfoResDto;

import com.link2room.aeriabots.facade.IWXMemberInfoFacadeService;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by LN on 2016/11/15.
 */
@Api(tags = {"微信会员信息"})
@RestController
@RequestMapping("/in/WxMemberInfos")
public class WxMemberInfoInsideController {
    @Resource
    private IWXMemberInfoFacadeService wxMemberInfoFacadeService;

    @ApiOperation(value = "微信会员信息", response = WxMemberInfoResDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "openid", required = true, value = "openid", dataType = "String", paramType = "query"),
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getMemberInfos(
            @RequestParam(name = "openid") String openid) throws Exception {
        BaseL2rParamDto paramDto = new BaseL2rParamDto();
        paramDto.setOpenid(openid);
        WxMemberInfoResDto resDto = null;
        List<WxMemberInfoResDto> resInfo = wxMemberInfoFacadeService.getMemberInfos(paramDto);
        if(CollectionUtils.isNotEmpty(resInfo)){
            resDto = resInfo.get(0);
        }

        BaseResultDto res = new BaseResultDto();
        res.setResultInfo(resDto);
        res.setResultCode(0);
        return res;
    }
}
